//
// Created by Semir on 2020/6/10.
//

#include <iostream>
#include <vector>
#include <string>

using namespace std;

static bool checkLegalStart(char c) {
    return (c <= '9' && c >= '0') || c == '+' || c == '-';
}

static bool checkLegal(char c) {
    return c <= '9' && c >= '0';
}

int StrToInt(string str) {
    if (str.empty() || !checkLegalStart(str[0])) {
        return 0;
    }
    long long res = 0;
    int i = 0;
    bool negative = false;
    if (str[0] == '+' || str[0] == '-') {
        if (str[0] == '-') {
            negative = true;
        }
        i++;
        if (i >= str.length()) {
            return 0;
        }
    }
    while (i < str.length()) {
        if (res >= 0 && checkLegal(str[i])) {
            res = res * 10 + (str[i] - '0');
        } else {
            return 0;
        }
        i++;
    }
    return negative ? -res : res;
}

int main() {
    long long ha = -2147483649;
    cout << ha << endl;
    string str = "-2147483649";
    int res = StrToInt(str);
    cout << res << endl;
    return 0;
}